package com.baizhi.wd.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.Person;
import com.baizhi.wd.service.TelbookService;
import com.baizhi.wd.service.TelbookServiceImpl;

public class QueryAllAction extends HttpServlet {
	public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
			try{
				//System.out.println(request.getParameter("id"));
				// 1 获取client数据
		
				// 2 调业务类的方法，查所有
				TelbookService ts = new TelbookServiceImpl();
				List<Person> allPersons = ts.getAllPersons();
				// request中存命名属性
				
				request.setCharacterEncoding("utf-8");
				request.setAttribute("List", allPersons);
				
				
				// 3 根据结果，跳转--请求转发
				RequestDispatcher rd = request.getRequestDispatcher("/per/queryAllView");
				rd.forward(request, response);
			} catch(Exception e){
				e.printStackTrace();
				// 统一到错误提示页--重定向
				response.sendRedirect("/telbook_2/catchError.html");
			}
		}
}
